home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Messaging / OSL / AEObjPak.c next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  9.3 KB  |  302 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        AEObjPak.c (Orignal name: AEObjectPacking.c)
  3.  
  4.     Contains:    
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>     9/29/94    RA        1189812: Mods for 68K build.
  13.          <2>     8/19/94    NP        1181622: Ownership fix.
  14.          <3>      2/7/94    NP        Tiger Team doings.
  15.          <2>     7/21/93    NP        Fixed #include
  16.          <1>     7/21/93    NP        first checked in
  17.  
  18.     To Do:
  19. */
  20.  
  21. /*———————————————————————————————————————————————————————————————————————————————————*/
  22. /*                                            
  23.     ©Apple Computer, Inc.  1992         
  24.           All Rights Reserved.                
  25.     Author: Eric House
  26.  
  27.             AEObjectPacking.p                
  28.              Object Support code for AppleEvents    
  29.                                             */
  30. #include <Types.h>
  31. #include <AEObjects.h>
  32. #include "OSLPriv.h"
  33.  
  34. /* AEObject packing is a collection of routines which facilitate packing the descriptors
  35. for object specifiers. The basic routines clean up after themselves, and also clean up
  36. descriptors passed to them if requested. The cleanup of passed descriptors DOES NOT 
  37. happen if the routine fails. 
  38.  
  39. Change History:
  40.     Original Code by Mike Farr & Kurt Piersol                    10/31/90
  41.  
  42. */
  43.  
  44.  
  45. /*——————————————————————————————————  INLINE  ———————————————————————————————————————*/
  46.  
  47. /*$S AEObjPacking */
  48. /*——————————————————————————————————— EXTERNAL ——————————————————————————————————————*/        
  49. /*$ifC Debug */
  50. extern void ReportError(Str255 errString, OSErr theError );
  51. /*$ENDC Debug */ 
  52.  
  53. /*————————————————————————————— FORWARD DECLARATIONS ————————————————————————————————*/        
  54.  
  55. /* The first param of PutTypeParam() was const -- but PutTypeParam()
  56. passed the params along to AEPutKeyPtr(), whose first param is not const 
  57. therefore , I decided to remove the const, instead of just letting CW ignore
  58. the fact...Adkins -- I remnoved the const.*/
  59.  
  60. OSErr PutTypeParam( AERecord *theRecord, AEKeyword field, DescType theType) ;
  61.  
  62.  
  63. /*————————————————————————————————— PROCEDURES ——————————————————————————————————————*/        
  64. /*———————————————————————————————————————————————————————————————————————————————————*/
  65.  
  66. #pragma segment AEObjPacking
  67.  
  68. pascal OSErr
  69. CreateCompDescriptor(    DescType comparisonOperator,
  70.                                 AEDesc *operand1,
  71.                                 AEDesc *operand2,
  72.                                 Boolean disposeInputs,
  73.                                 AEDesc *theDescriptor)
  74. {
  75. /*Like the makeObjDescriptor routine above, this a handy packing routine. It has the same 
  76. characteristics and limitations. However, it packs up a comparison record*/
  77.         
  78.     AERecord compRecord ;
  79.     OSErr result ;    
  80.  
  81.     compRecord.dataHandle = NULL;
  82.     
  83.     FailErr( AECreateList( NULL, 0, true, &compRecord ), result, errExit ); /*create the record.*/ 
  84.                     
  85.     /*Pack the comparison operator*/
  86.     FailErr( AEPutKeyPtr( &compRecord, keyAECompOperator, typeEnumerated,
  87.                 (Ptr)&comparisonOperator, sizeof(comparisonOperator) ), result, errExit  ) ;
  88.  
  89.     /*Pack operand 1, the left hand side*/
  90.     FailErr( AEPutKeyDesc( &compRecord, keyAEObject1, operand1 ), result, errExit  ) ;
  91.  
  92.     /*Pack operand 2, the right hand side*/
  93.     FailErr( AEPutKeyDesc( &compRecord, keyAEObject2, operand2 ), result, errExit  ) ;
  94.  
  95.     /*autodispose if requested*/
  96.     if ( disposeInputs ) 
  97.     {
  98.         IgnoreOSErr( AEDisposeDesc( operand1 ) ) ;
  99.         IgnoreOSErr( AEDisposeDesc( operand2 ) ) ;
  100.     } 
  101.     
  102.     /*coerce record to descriptor*/
  103.     result = AECoerceDesc( &compRecord, typeCompDescriptor, theDescriptor ) ;
  104.     IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
  105.     return result ;
  106.  
  107. errExit :
  108.  
  109. #ifdef Debug
  110.     ReportError('comparison desc could not be made',err);
  111. #endif
  112.     /*dispose record we created*/
  113.     IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
  114.     
  115.     return result ;
  116. }
  117.  
  118. /*———————————————————————————————————————————————————————————————————————————————————*/
  119. pascal OSErr
  120. CreateCompEventDesc(    DescType compEventClass,
  121.                         DescType compEventID,
  122.                         AERecord *args,
  123.                         Boolean disposeInputs,
  124.                         AEDesc *theDescriptor )
  125. {        
  126.     AERecord compRecord ;
  127.     OSErr err = noErr ;    
  128.  
  129.     compRecord.dataHandle = NULL ;
  130.     
  131.     FailErr( AECreateList( NULL, 0, true, &compRecord ), err, errExit ) ;  
  132.  
  133. // stuff in the event class and id (these are not attributes!!!)
  134.     FailErr( AEPutKeyPtr( &compRecord, keyEventClassParam, typeType, 
  135.             (Ptr)&compEventClass, sizeof(compEventClass) ), err, errExit ) ;
  136.  
  137.     FailErr( AEPutKeyPtr( &compRecord, keyEventIDParam, typeType,
  138.             (Ptr)&compEventID, sizeof(compEventID) ), err, errExit ) ;
  139.  
  140. // Stuff in the params
  141.     FailErr( AEPutKeyDesc( &compRecord, keyCompEvtParams, args ),
  142.             err, errExit  ) ;
  143.  
  144.     // autodispose if requested
  145.     if ( disposeInputs ) 
  146.     {
  147.         IgnoreOSErr( AEDisposeDesc( args ) ) ;
  148.     } 
  149.     
  150.     // coerce record to descriptor
  151.     FailErr( AECoerceDesc( &compRecord, typeCompEvtDescriptor, theDescriptor ),
  152.             err, errExit ) ;
  153.     IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
  154.  
  155. FAIL_ERR_PROC(err, errExit)
  156.     // no need to check if non-null
  157.     IgnoreOSErr( AEDisposeDesc( &compRecord ) ) ;
  158. END_FAIL_ERR_PROC(err)
  159. }
  160.  
  161. /*———————————————————————————————————————————————————————————————————————————————————*/
  162.  
  163. pascal OSErr CreateOffsetDescriptor(
  164.                             long theOffset ,
  165.                             AEDesc *theDescriptor )
  166.                             
  167. {
  168.     return AECreateDesc( typeLongInteger, (Ptr)&theOffset, 4, theDescriptor ) ;
  169. }
  170.  
  171. /*———————————————————————————————————————————————————————————————————————————————————*/
  172. pascal OSErr
  173. CreateLogicalDescriptor(
  174.                             AEDescList *theLogicalTerms,         /*a list of comb and logi terms*/
  175.                             DescType theLogicOperator,             /*the operator, e.g. AND*/    
  176.                             Boolean disposeInputs,
  177.                             AEDesc *theDescriptor )     /*the result, a LogicalRecord*/
  178. {
  179.     AERecord theRecord ;
  180.     OSErr err ;
  181.         
  182.     theRecord.dataHandle = NULL;
  183.     FailErr( AECreateList(NULL, 0, true, &theRecord ), err, errExit ) ;        /*Make the record*/
  184.                                 
  185.     /*now stuff the terms of the logical combination*/
  186.     FailErr( AEPutKeyDesc( &theRecord, keyAELogicalTerms, theLogicalTerms),
  187.             err, errExit ) ;
  188.     
  189.     /*stuff the logical combination operator*/
  190.     FailErr(AEPutKeyPtr( &theRecord, keyAELogicalOperator, typeEnumerated,
  191.             (Ptr)&theLogicOperator, sizeof(theLogicOperator)), err, errExit );
  192.     
  193.     /*autodispose if requested*/
  194.     if ( disposeInputs )
  195.         IgnoreOSErr( AEDisposeDesc(theLogicalTerms) );
  196.     
  197.     /*coerce record to descriptor*/
  198.     err = AECoerceDesc( &theRecord, typeLogicalDescriptor, theDescriptor ) ;
  199.  
  200.  
  201. errExit :
  202.  
  203.     /*dispose record we created*/
  204.     IgnoreOSErr( AEDisposeDesc( &theRecord ) ) ;
  205.     return err ;
  206. } /* CreateLogicalDescriptor */
  207.  
  208.  
  209. /*———————————————————————————————————————————————————————————————————————————————————*/
  210. pascal OSErr CreateObjSpecifier(        DescType desiredClass,
  211.                                 AEDesc *theContainer, 
  212.                                 DescType keyForm ,
  213.                                 AEDesc *keyData, 
  214.                                 Boolean disposeInputs,
  215.                                 AEDesc *objSpecifier )
  216.  
  217. /*The primary utility routine, this packages up the parameters and makes a complete 
  218. object specifier out of them. It may also perform some storage management tasks, if
  219. the client so requests.*/
  220.         
  221. {
  222.     AERecord objRecord;
  223.     OSErr err ;
  224.  
  225.     objRecord.dataHandle = NULL;
  226.     FailErr(AECreateList( NULL, 0, true, &objRecord ), err, errExit );
  227.                                         
  228.     /*Pack the desired type.*/
  229.     FailErr( PutTypeParam( &objRecord, keyAEDesiredClass, desiredClass), err, errExit  ) ;
  230.                     
  231.     /*pack the descriptor of the containing object*/
  232.     FailErr( AEPutKeyDesc( &objRecord, keyAEContainer, theContainer ), err, errExit );
  233.     
  234.     /*if client asked for inputs to be disposed, toss them away. No errors should be possible!*/
  235.     if ( disposeInputs )
  236.         IgnoreOSErr( AEDisposeDesc( theContainer ) ) ;
  237.         
  238.     /*pack the selection form (or naming form)*/
  239.     FailErr( AEPutKeyPtr( &objRecord, keyAEKeyForm, typeEnumerated, (Ptr)&keyForm, 4 ), err, errExit  ) ;
  240.  
  241.     /*pack the selection data*/
  242.     FailErr(AEPutKeyDesc( &objRecord, keyAEKeyData, keyData ), err, errExit ) ;
  243.  
  244.     /*again, an automatic and supposedly successful dispose*/
  245.     if ( disposeInputs )
  246.         IgnoreOSErr( AEDisposeDesc( keyData ) ) ;
  247.     
  248.     /* Lastly, turn our painstakingly constructed record into an object descriptor */
  249.     err = AECoerceDesc( &objRecord, typeObjectSpecifier, objSpecifier ) ;
  250.  
  251.  
  252. errExit:
  253.     /*dispose record we created*/
  254.     IgnoreOSErr( AEDisposeDesc( &objRecord ) ) ;
  255.     return err ;
  256. }
  257.  
  258. /*———————————————————————————————————————————————————————————————————————————————————*/
  259. pascal OSErr CreateRangeDescriptor(
  260.                             AEDesc *rangeStart ,      /*either a number or 'prev', 'next' etc.*/
  261.                             AEDesc *rangeStop ,         /*tells you which one it is*/    
  262.                             Boolean disposeInputs ,
  263.                             AEDesc *theDescriptor )     /*the result, a rangeRecord*/
  264. {
  265.     AERecord theRecord ;
  266.     OSErr err ;
  267.  
  268.  
  269.     theRecord.dataHandle = NULL ;
  270.     FailErr( AECreateList( NULL, 0, true, &theRecord ), err, errExit );        /*Make the record*/
  271.                                 
  272.     /*now stuff the start and stop objects*/
  273.     FailErr( AEPutKeyDesc( &theRecord, keyAERangeStart, rangeStart), err, errExit);
  274.     FailErr( AEPutKeyDesc( &theRecord, keyAERangeStop, rangeStop), err, errExit);
  275.     
  276.     /*autodispose if requested*/
  277.     if ( disposeInputs ) 
  278.     {
  279.         IgnoreOSErr(AEDisposeDesc(rangeStart));
  280.         IgnoreOSErr(AEDisposeDesc(rangeStop)) ;
  281.     }
  282.  
  283.     /*coerce record to descriptor*/
  284.     err = AECoerceDesc( &theRecord, typeRangeDescriptor, theDescriptor);
  285.  
  286. errExit:
  287.     IgnoreOSErr( AEDisposeDesc( &theRecord ) ) ;
  288.      return err ;
  289. }
  290.  
  291. /*———————————————————————————————————————————————————————————————————————————————————*/
  292.  
  293. /* Adkins -- I removed the const on the first param, case AEPutKeyPtr does not
  294. take a const param. CW ignores this apparently...*/
  295.  
  296. static OSErr PutTypeParam( AERecord *theRecord, AEKeyword field, DescType theType )
  297.  
  298. /*a handy utility routine to put a 4 chr parameter of typeType into an AERecord.*/
  299. {
  300.     return AEPutKeyPtr( theRecord, field, typeType, (Ptr)&theType, 4 ) ;
  301. }
  302.